package cn.kgc.kgde.bookstore.config;

/**
 * @author xiaodai
 * @create 2022-06-15 14:25
 */

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.boot.context.properties.ConfigurationProperties;


import javax.annotation.PostConstruct;

/**
 * 读取配置文件
 */
@Configuration
@ConfigurationProperties(prefix = "alipay")//读取yml中的alipay
@PropertySource("classpath:/application.yml")
@Data
@Component
public class AliPayConfig {
    private String appId;//应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    private String appPrivateKey;//商户私钥，您的PKCS8格式RSA2私钥
    private String alipayPublicKey;//支付宝公钥,
    private String notifyUrl;//服务器异步通知页面路径需http://格式的完整路径，不能加?id=123这类自定义参数



    @PostConstruct
    public void init() {
        // 设置参数（全局只需设置一次）
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi.alipaydev.com";
        config.signType = "RSA2";
        config.appId = this.appId;
        config.merchantPrivateKey = this.appPrivateKey;
        config.alipayPublicKey = this.alipayPublicKey;
        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
        System.out.println("=======支付宝SDK初始化成功=======");
    }
}
